<link rel="stylesheet" type="text/css" href="<?php echo TEMPLATES_PATH;?>/css/myhome.css">
<style>.custom-b{cursor: pointer;}.select-ys{color: white !important;}#single,#twin,#three{color: #eb6876;}.msg_del{background-position:0}</style>
<script type="text/javascript">
	$(function(){
		$('.layout .container .line ul>li').bind('click',function(){
			$(this).addClass('select-ys').siblings('li').removeClass('select-ys');
			$('.layout #main>div').hide().eq($(this).index()).show();
			$('.m_msg').hide().eq($(this).index()).show();
		});
	});
</script>
<header class="layout head padding-small">
	<a href="javascript:pageBack();" class="hBack float-left"></a>
	<h4 class="hTxt float-left text-center text-white">站内信</h4>
	<a href="javascript:;" id="btnJdkey" class="hHlep float-right"></a>
</header>
<div class="msg_type">
    <div class="type_item t_cur">系统消息</div>
    <div class="type_item">私信</div>
    <div class="type_item">留言</div>
</div>
<div class="m_msg">
    <div class="m_list"></div>
    <div class="new-load-more" style="text-align:center;" id="s_more_hi"><span style="font-size:12px;">加载更多</span></div>
</div>
<div class="m_msg" style="display:none;">
    <div class="m_list"></div>
    <div class="new-load-more" style="text-align:center;" id="p_more_hi"><span style="font-size:12px;">加载更多</span></div>
</div>
<div class="m_msg" style="display:none;">
    <div class="m_list"></div>
    <div class="new-load-more" style="text-align:center;" id="f_more_hi"><span style="font-size:12px;">加载更多</span></div>
</div>
<input type="hidden" id="spage" value="" />
<input type="hidden" id="ppage" value="" />
<input type="hidden" id="fpage" value="" />

<script type="text/javascript">
    $('.type_item').click(function(){
        var index = $(this).index();
        $(this).addClass('t_cur').siblings('.type_item').removeClass('t_cur');
        $('.m_msg').eq(index).show().siblings('.m_msg').hide();
    })

    $(function(){
        $('#spage').val("1");
        $('#ppage').val("1");
        $('#fpage').val("1");
        getSysMsg();
        getPveMsg();
        getFebMsg();
    });
    $('#s_more_hi').click(function(){
        getSysMsg();
    })

    $('#p_more_hi').click(function(){
        getPveMsg();
    })

    $('#f_more_hi').click(function(){
        getFebMsg();
    })

    function getSysMsg(){
        jQuery.getJSON('index.php?act=member_msg&op=systemMsg',{curpage:$('#spage').val()},function(d){
            if(d.state){
                jQuery.each(d.message_array,function(i,v){
                    var content = '<dl>'
                        + '<dt class="msg_tit">FROM：'+v.from_member_name+(v.message_open == '1' ? '<a href="javascript:;" onclick="noRead(this,'+v.message_id+','+v.message_type+')" class="no_read">取消已读</a>':'<a href="javascript:;" onclick="isRead(this,'+v.message_id+','+v.message_type+')" class="is_read">标记已读</a>')+'<a href="javascript:;" onclick="delMsg(this,'+v.message_id+','+v.message_type+')" class="msg_del"></a></dt>'
                        + '<dd class="msg_con">'+v.message_body+'</dd>'
                        + '<dd class="msg_time">'+v.message_time+'</dd>'
                        + '</dl>';
                    $('.m_msg').eq(0).children('.m_list').append(content);
                })
                $('#spage').val(parseInt($('#spage').val())+1);
            }else{
                $('#s_more_hi').remove();
                $('.m_msg').eq(0).append('<div style="text-align:center;margin:40px;font-size:13px;">抱歉暂时没有相关结果</div>');
            }
        })
    }
    function getPveMsg(){
        jQuery.getJSON('index.php?act=member_msg&op=privateMsg',{curpage:$('#ppage').val()},function(d){
            if(d.state){
                jQuery.each(d.message_array,function(i,v){
                    var content = '<dl>'
                        + '<dt class="msg_tit">FROM：'+v.from_member_name+(v.message_open == '1' ? '<a href="javascript:;" onclick="noRead(this,'+v.message_id+','+v.message_type+')" class="no_read">取消已读</a>':'<a href="javascript:;" onclick="isRead(this,'+v.message_id+','+v.message_type+')" class="is_read">标记已读</a>')+'<a href="javascript:;" onclick="delMsg(this,'+v.message_id+','+v.message_type+')" class="msg_del"></a></dt>'
                        + '<dd class="msg_con">'+v.message_body+'</dd>'
                        + '<dd class="msg_time">'+v.message_time+'</dd>'
                        + '</dl>';
                    $('.m_msg').eq(1).children('.m_list').append(content);
                })
                $('#ppage').val(parseInt($('#ppage').val())+1);
            }else{
                $('#p_more_hi').remove();
                $('.m_msg').eq(1).append('<div style="text-align:center;margin:40px;font-size:13px;">抱歉暂时没有相关结果</div>');
            }
        })
    }
    function getFebMsg(){
        jQuery.getJSON('index.php?act=member_msg&op=feedbackMsg',{curpage:$('#fpage').val()},function(d){
            if(d.state){
                jQuery.each(d.message_array,function(i,v){
                    var content = '<dl>'
                        + '<dt class="msg_tit">FROM：'+v.from_member_name+(v.message_open == '1' ? '<a href="javascript:;" onclick="noRead(this,'+v.message_id+','+v.message_type+')" class="no_read">取消已读</a>':'<a href="javascript:;" onclick="isRead(this,'+v.message_id+','+v.message_type+')" class="is_read">标记已读</a>')+'<a href="javascript:;" onclick="delMsg(this,'+v.message_id+','+v.message_type+')" class="msg_del"></a></dt>'
                        + '<dd class="msg_con">'+v.message_body+'</dd>'
                        + '<dd class="msg_time">'+v.message_time+'</dd>'
                        + '</dl>';
                    $('.m_msg').eq(2).children('.m_list').append(content);
                })
                $('#fpage').val(parseInt($('#fpage').val())+1);
            }else{
                $('#f_more_hi').remove();
                $('.m_msg').eq(2).append('<div style="text-align:center;margin:40px;font-size:13px;">抱歉暂时没有相关结果</div>');
            }
        })
    }
    //标记已读
    function isRead(obj,msg_id,type_id){
        jQuery.getJSON('index.php?act=member_msg&op=isRead',{msg_id:msg_id,type_id:type_id},function(d){
            if(d.state){
                $(obj).removeClass('is_read').addClass('no_read');
                $(obj).html('取消已读');
                $(obj).attr('onclick','noRead(this,'+msg_id+','+type_id+')');
            }else{
                alert('标记已读失败');
            }
        })
    }

    //取消已读
    function noRead(obj,msg_id,type_id){
        jQuery.getJSON('index.php?act=member_msg&op=noRead',{msg_id:msg_id,type_id:type_id},function(d){
            if(d.state){
                $(obj).removeClass('no_read').addClass('is_read');
                $(obj).html('标记已读');
                $(obj).attr('onclick','isRead(this,'+msg_id+','+type_id+')');
            }else{
                alert('取消已读失败');
            }
        })
    }
    //删除消息
    function delMsg(obj,msg_id,type_id){
        if(confirm('您是否确定要删除该消息？')){
            jQuery.getJSON('index.php?act=member_msg&op=delMsg',{msg_id:msg_id,type_id:type_id},function(d){
                if(d.state){
                    $(obj).parents('dl').remove();
                }else{
                    alert('该消息删除失败');
                }
            })
        }
    }

</script>